![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@npmcli/map-workspaces
Advanced tools
Retrieves a name:pathname Map for a given workspaces config
The @npmcli/map-workspaces package is designed to assist with managing and interacting with npm workspaces. It provides functionality to map and iterate over workspaces in a project, allowing for operations such as executing scripts or installing dependencies in each workspace. This can be particularly useful in monorepo setups where multiple packages are managed within a single repository.
Mapping Workspaces
This feature allows you to map all the workspaces defined in your project. The code sample demonstrates how to use @npmcli/map-workspaces to retrieve a list of workspaces based on the configuration in your package.json. This is useful for scripts that need to perform actions on each workspace.
const mapWorkspaces = require('@npmcli/map-workspaces');
const { workspaces } = await mapWorkspaces({
cwd: process.cwd(),
pkg: {
workspaces: [
'packages/*'
]
}
});
console.log(workspaces);
Lerna is a tool for managing JavaScript projects with multiple packages, known as a monorepo. It provides similar functionalities to @npmcli/map-workspaces by allowing you to run scripts, publish packages, and more across multiple workspaces. However, Lerna is more feature-rich and can handle complex workflows, including versioning and publishing.
Yarn Workspaces is a feature built into Yarn that automatically manages the installation of dependencies and linking of packages in a monorepo. It offers similar workspace mapping functionalities but is tightly integrated with Yarn's package management capabilities. Unlike @npmcli/map-workspaces, Yarn Workspaces is not a separate package but a feature of Yarn itself.
Retrieves a name:pathname Map for a given workspaces config.
Long version: Reads the workspaces
property from a valid workspaces configuration object and traverses the paths and globs defined there in order to find valid nested packages and return a Map of all found packages where keys are package names and values are folder locations.
npm install @npmcli/map-workspaces
const mapWorkspaces = require('@npmcli/map-workspaces')
await mapWorkspaces({
cwd,
pkg: {
workspaces: {
packages: [
"a",
"b"
]
}
}
})
// ->
// Map {
// 'a': '<cwd>/a'
// 'b': '<cwd>/b'
// }
Given a folder structure such as:
├── package.json
└── apps
├── a
│ └── package.json
├── b
│ └── package.json
└── c
└── package.json
const mapWorkspaces = require('@npmcli/map-workspaces')
await mapWorkspaces({
cwd,
pkg: {
workspaces: [
"apps/*"
]
}
})
// ->
// Map {
// 'a': '<cwd>/apps/a'
// 'b': '<cwd>/apps/b'
// 'c': '<cwd>/apps/c'
// }
mapWorkspaces(opts) -> Promise<Map>
opts
:
pkg
: A valid package.json
Objectcwd
: A String defining the base directory to use when reading globs and paths.ignore
: An Array of paths to be ignored when using globs to look for nested package.A Map in which keys are package names and values are the pathnames for each found workspace.
FAQs
Retrieves a name:pathname Map for a given workspaces config
The npm package @npmcli/map-workspaces receives a total of 558,766 weekly downloads. As such, @npmcli/map-workspaces popularity was classified as popular.
We found that @npmcli/map-workspaces demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.